-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyQVM #552
PyQVM #552
Conversation
YAY! |
- measure all qubits on a qc (not just the ones used in a program) - return as a dict instead of a 2d numpy array because of sparsely indexed qubits
- remove classical addresses. You just get everything now - all the shimmy things in QAM are now "private". Don't use these
we need to get a qvm running on semaphore ...
Adding a 👍for another use of this merge. Currently to make noise model templates it's very useful to have matrix representations of all the standard gates accessible in the library. Right now I'm using |
import numpy as np | ||
import cmath | ||
|
||
I = np.array([[1.0, 0.0], [0.0, 1.0]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be refactored to be attributes on the existing gate.py
objects? This would reduce any namespace confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good suggestion. I think I'm still leaning towards ^^ for the following reasons
- freer to define matrices that aren't actually Quil instructions. cf
P0
- I personally think this is a good demonstration of how namespaces can be a honking great idea*
* from a python console try import this
pyquil/pyqvm.py
Outdated
raise RuntimeError("Improper program - Jump Target not found in the " | ||
"input program!") | ||
|
||
def transition(self, run_and_measure=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing CONVERT
, EXCHANGE
, LOAD
, STORE
, EQ
, GT
, GE
, LT
, LE
.
self.wf_simulator.reset() | ||
self.program_counter += 1 | ||
|
||
elif isinstance(instruction, Declare): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the offset get stored? Should we add a disclaimer that SHARING
is not supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
# Label; pass straight over | ||
self.program_counter += 1 | ||
|
||
elif isinstance(instruction, JumpConditional): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work fine with the deferred measurement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean? what's being deferred?
else: | ||
right_val = instruction.right | ||
|
||
if isinstance(instruction, ClassicalAnd): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an approximation of the behavior that should happen. (e.g., it should not be possible to add two bits) Each instruction has roughly an "addressing mode" of supported data types.
just jumping in here to say that we should think hard on what sort of API we want to expose as part of the |
pyquil/reference_simulator.py
Outdated
if not isinstance(operator, PauliSum): | ||
operator = PauliSum([operator]) | ||
|
||
sum = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return sum([_term_expectation(self.wf, term, n_qubits=self.n_qubits) for termin operator])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no list
This has an incredible test suite 🎉 |
@ncrubin gets all (most) of the credit for the test suite |
Have been using this a bit recently. I would like to suggest that the API for using the pyQVM and the lisp QVM should be more similar. For example, if I want the wavefunction amplitudes from lisp QVM, I do this:
but on pyQVM, I do this:
If someone wanted to write an app where the backend were interchangeable, this would cause difficulty. |
wf_sim = NumpyWavefunctionSimulator(n_qubits)
amplitudes = wf_sim.do_program(program).wf but we can also add a method Note that each simulator ( |
I'd like to echo Keri's comment - can we get to a point where simulators/QVMs have a smaller and more uniform interface? |
@mpharrigan (CC @karalekas) To what extent have Keri/Steven's comments been addressed? The PR is 4k lines now, and it doesn't show any new updates on that front. FWIW, "API confusion"/impedance mismatch between interfaces is my primary concern. |
I'll open a follow-on ticket for implementing |
Simulate quantum programs without ever leaving the comfort of your python environment. Note: not as performant for large numbers of qubits as the QVM
Includes:
ReferenceXxxSimulators ported and cleaned up from https://github.com/rigetticomputing/reference-qvm